package nccloud.web.hrppl.pjapplication.pjappl.action;
import nc.itf.hrppl.pjapplication.pjappl.IPJApplHVOService;
import nc.itf.uif.pub.IUifService;
import nc.mddb.baseutil.MDDAOUtil;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.hrppl.pjapplication.AggPjapplVO;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.ui.model.row.Cell;
import nccloud.framework.web.ui.model.row.Row;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.web.codeplatform.framework.action.base.*;

/**
 * ׼��Action
 */
public class WarehousingAction extends BaseAction{
	@Override
	public Object doAction(IRequest request, RequstParamWapper paramWapper) throws Throwable{
		//json����ת��
		RequestDTO param = VOTransform.toVO(paramWapper.requestString,RequestDTO.class);
		//��ȡ����
		String pk = param.getPk();
		String[] pks = pk.split("_");
		IPJApplHVOService service = ServiceLocator.find(IPJApplHVOService.class);
		// modify by wy at ����Ŀ׼�� 2024��8��26��
		AggPjapplVO vo = null;
		for(String pkk : pks) {
			if("".equals(pkk)) continue;
			vo = service.warehousing(pkk);
		}
//		AggPjapplVO vo = service.warehousing(pk);
		if(vo == null){
			return null;
		}
		ResultWapper o = (ResultWapper) buildResult(param,true,null,vo);
		ExtBillCard data = (ExtBillCard) o.getData();
		Row row = data.getHead().getModel().getRows()[0];
		Cell expertgroupmember = row.getValues().get("expertgroupmember");
		if (expertgroupmember != null && expertgroupmember.getValue() != null){
			String value = expertgroupmember.getValue().toString();
			if (value.contains(",")){
				IUifService uifService = ServiceLocator.find(IUifService.class);
				DefdocVO[] defdocVOS = (DefdocVO[]) uifService.queryByCondition(DefdocVO.class, " name in " + MDDAOUtil.getInSql(value.split(",")) + " or pk_defdoc in " + MDDAOUtil.getInSql(value.split(",")));
				if (defdocVOS != null && defdocVOS.length > 0){
					StringBuffer sb_display = new StringBuffer();
					StringBuffer sb_value = new StringBuffer();
					for (DefdocVO defdocVO : defdocVOS) {
						sb_display.append(defdocVO.getName()).append(",");
						sb_value.append(defdocVO.getPk_defdoc()).append(",");
					}
					expertgroupmember.setDisplay(sb_display.deleteCharAt(sb_display.length() - 1).toString());
					expertgroupmember.setValue(sb_value.deleteCharAt(sb_value.length() - 1).toString());
				}
			}
		}
		return o;
	}
	
}